package com.piggy.sys.api.factory;

import com.piggy.common.core.domain.R;
import com.piggy.common.core.utils.sms.SmsConfig;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.sys.api.RemoteSmsService;
import com.piggy.sys.api.bo.SmsNotify;
import com.piggy.sys.api.bo.SysEmailBo;
import com.piggy.sys.api.bo.SysSmsBo;
import com.piggy.sys.api.bo.SysSmsQueryBo;
import com.piggy.sys.api.vo.SysSmsVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 系统配置服务降级处理
 *
 * @author shark
 */
@Component
public class RemoteSmsFallbackFactory implements FallbackFactory<RemoteSmsService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteSmsFallbackFactory.class);

    @Override
    public RemoteSmsService create(Throwable throwable) {
        log.error("客户端调用失败:{}", throwable.getMessage());
        return new RemoteSmsService()
        {
            @Override
            public R<Boolean> userRegSendSms(String phone, String source) {
                return R.fail("获取客户端失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> createAccount(String phone, String password, String company, String regTime, String source) {
                return R.fail("获取客户端失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> resetPasswd(String phone, String password, String company, String source) {
                return R.fail("获取客户端失败:" + throwable.getMessage());
            }

            @Override
            public R<SmsConfig> getConfig(String source) {
                return R.fail("获取客户端失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> sendMail(SysEmailBo emailBo, String source) {
                return R.fail("获取客户端失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> sendSms(SysSmsBo bo, String source) {
                return R.fail("获取客户端失败:" + throwable.getMessage());
            }

            @Override
            public TableDataInfo<SysSmsVo> list(SysSmsQueryBo bo, String source) {
                return null;
            }

            @Override
            public R<Boolean> waybillNotify(String phone, String waybillNo, String status, String nextStatus, String source) {
                return null;
            }

            @Override
            public R<Boolean> scheduleNotify(String phone, String scheduleNo, String status, String nextStatus, String source) {
                return null;
            }

            @Override
            public R<Boolean> smsNotify(String phone, SmsNotify smsNotify, String source) {
                return null;
            }
        };
    }
}
